package il.technion.cs236369.interfaces;

import il.technion.cs236369.exceptions.DatabaseException;
import il.technion.cs236369.exceptions.NotFoundException;
import il.technion.cs236369.exceptions.NotValidException;

import java.io.IOException;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;

public interface ICacheManager {

	/**
	 * Stores the response
	 * 
	 * @param response The response to store
	 * @return True iff the response was stored
	 * @throws DatabaseException If there are any problems connecting to the
	 *             database
	 * @throws IOException 
	 */
	public boolean store(String URL, HttpResponse response) throws DatabaseException, IOException;

	/**
	 * Loads a saved response
	 * 
	 * @param request The request to load
	 * @return The saved response
	 * @throws NotFoundException If the response was not stored
	 * @throws NotValidException If the currently saved entry is no longer valid
	 *             and cannot be refreshed
	 * @throws DatabaseException If there are any problems connecting to the
	 *             database
	 */
	public HttpResponse load(HttpRequest request) throws NotFoundException, DatabaseException, NotValidException;

	/**
	 * Checks if a given url is stored
	 * 
	 * @param request The request to check
	 * @return True iff the url was cached before
	 * @throws DatabaseException If there are any problems connecting to the
	 *             database
	 */
	public boolean contains(HttpRequest request) throws DatabaseException;
	
	/**
	 * Clears the cache of all data
	 * @throws DatabaseException 
	 */
	public void clear() throws DatabaseException;
}
